<template>
	<view class="nbxx-page">
		<!-- 加载状态 -->
		<view v-if="loading" class="loading-container">
			<text class="loading-text">加载中...</text>
		</view>
		
		<!-- 年报信息列表 -->
		<view v-else-if="nbxxList.length > 0" class="nbxx-container">
			<view class="nbxx-item" v-for="(item, index) in nbxxList" :key="index">
				<!-- 左侧图标 -->
				<view class="item-icon">
					<image class="icon-image" src="https://apizx01.sc798.com/Resource/home/ms1.png" mode="aspectFit"></image>
				</view>
				
				<!-- 中间内容 -->
				<view class="item-content">
					<text class="item-title">{{ item.title || item.reportName || '年报报告' }}</text>
					<text class="item-date">发布时间：{{ item.date || item.reportDate || '-' }}</text>
				</view>
				
				<!-- 右侧箭头 -->
				<view class="item-arrow">
					<image class="arrow-image" src="https://apizx01.sc798.com/Resource/home/rig.png" mode="aspectFit"></image>
				</view>
			</view>
		</view>
		
		<!-- 空数据状态 -->
		<view v-else class="empty-container">
			<text class="empty-text">暂无年报信息</text>
		</view>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 年报信息数据
const nbxxList = ref([])
const loading = ref(false)

// 调用API获取年报信息
const fetchNbxxInfo = async (requestData) => {
	try {
		loading.value = true
		console.log('发送年报信息请求参数:', requestData)
		
		// 发送POST请求到 /enterprise/basic/basic
		const response = await uni.request({
			url: 'https://apizx01.sc798.com/api/proxy/enterprise/basic/basic',
			method: 'POST',
			data: requestData,
			header: {
				'content-type': 'application/x-www-form-urlencoded'
			}
		})
		
		console.log('年报信息响应:', response)
		
		// 处理响应数据
		if (response.data.code === 200) {
			nbxxList.value = response.data.rows || []
			console.log('年报信息数据:', nbxxList.value)
		} else {
			console.log('响应状态码不是200:', response.data?.code)
			uni.showToast({
				title: '获取年报信息失败',
				icon: 'none'
			})
		}
	} catch (error) {
		console.error('获取年报信息失败:', error)
		uni.showToast({
			title: '获取年报信息失败',
			icon: 'none'
		})
	} finally {
		loading.value = false
	}
}

onMounted(() => {
	console.log('年报信息页面已加载')
	
	// 获取页面参数
	const pages = getCurrentPages()
	const currentPage = pages[pages.length - 1]
	const options = currentPage.options
	
	// 获取requestData参数
	if (options.requestData) {
		try {
			const requestData = JSON.parse(decodeURIComponent(options.requestData))
			console.log('接收到的requestData:', requestData)
			fetchNbxxInfo(requestData)
		} catch (error) {
			console.error('解析requestData失败:', error)
			uni.showToast({
				title: '参数解析失败',
				icon: 'none'
			})
		}
	}
})
</script>

<style lang="scss" scoped>
.nbxx-page {
	min-height: 100vh;
	background-color: #F4F5F7;
}

.loading-container {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 400rpx;
	
	.loading-text {
		font-family: 'Alibaba PuHuiTi', sans-serif;
		font-weight: 400;
		font-size: 28rpx;
		color: #666666;
	}
}

.empty-container {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 400rpx;
	
	.empty-text {
		font-family: 'Alibaba PuHuiTi', sans-serif;
		font-weight: 400;
		font-size: 28rpx;
		color: #999999;
	}
}

.nbxx-container {
	padding: 29rpx 24rpx;
	display: flex;
	flex-direction: column;
	gap: 20rpx;
}

.nbxx-item {
	width: 704rpx;
	height: 127rpx;
	background: #FFFFFF;
	border-radius: 20rpx;
	display: flex;
	align-items: center;
	padding: 0 28rpx 0 33rpx;
	box-sizing: border-box;
	
	.item-icon {
		width: 60rpx;
		height: 60rpx;
		background: #F2F4F8;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 16rpx;
		flex-shrink: 0;
		
		.icon-image {
			width: 30rpx;
			height: 36rpx;
		}
	}
	
	.item-content {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		
		.item-title {
			font-family: 'Alibaba PuHuiTi', sans-serif;
			font-weight: 600;
			font-size: 30rpx;
			color: #000000;
			line-height: 1.2;
			margin-bottom: 15rpx;
		}
		
		.item-date {
			font-family: 'Alibaba PuHuiTi', sans-serif;
			font-weight: 400;
			font-size: 24rpx;
			color: #9B9B9B;
			line-height: 1.2;
		}
	}
	
	.item-arrow {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-shrink: 0;
		
		.arrow-image {
			width: 18rpx;
			height: 32rpx;
		}
	}
}
</style>
